<?php

session_start();
if( isset( $_POST['tkn'] ) ){

	#获取前台数据
	if( isset( $_POST['name'] ) ){
		$name  = mb_convert_encoding( $_POST['name'] , "utf-8" , "GBK" );
		$phone = mb_convert_encoding( $_POST['phone'] , "utf-8" , "GBK" );
		$qq   = mb_convert_encoding( $_POST['qq'] , "utf-8" , "GBK" );
		$class= mb_convert_encoding( $_POST['class'] , "utf-8" , "GBK" );
		
		sendmail( $name , $phone , $msg , $class );

	}else{
		echo "<script>alert( '邮件发送失败' );</script>";
	}

}else{
	echo "<script>alert( '重复提交' );</script>";
}


#邮件处理函数
function sendmail( $nm , $ph , $qq , $cls ){

	require_once( "mail/class.phpmailer.php" );
	require_once( "mail/class.smtp.php" );
	#设置时区
	date_default_timezone_set( "Asia/Shanghai" );

	$mail = new PHPMailer();

	#设置发送形势smtp
	$mail->IsSmtp();

	#设置编码
	$mail->CharSet = 'utf-8';

	#设置测试类型
	$mail->SMTPDebug = 1;

	#启用smtp的验证功能
	$mail->SMTPAuth = true;

	#发送方邮箱服务器
	$mail->Host = "smtp.163.com";

	#邮件发送端口
	$mail->Port = 25;

	#发送邮件的账号
	$mail->Username = "lgltlong@163.com";

	#发送邮件的密码
	$mail->Password = "Guoliang1989";

	#添加接收方账号
	$mail->AddAddress( "2475992603@qq.com" , "我的QQ" );

	#邮件标题
	$mail->Subject = "测试php发送邮件";

	#设置发件人信息
	$mail->From = "lgltlong@163.com";

	#发件人名字
	$mail->FromName = "测试";

	#邮件内容
	$mail->Body = "姓名：$nm , 电话 ：$ph , qq ： $qq , 课程：$cls";

	#发送
	if( $mail->send() ){
		echo "send success<br>";
	}else{
		echo "failed";
		echo "because :" . $mail->ErrorInfo;
	}

}
